package com.mask.im.common.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * @author jian
 */
public class BeanCopy {

	public static <T> T singleCopy(Object source, Class<T> target){

			T newInstance=null;
			try {
				 newInstance = target.newInstance();
				BeanUtils.copyProperties(source,newInstance);
			} catch (InstantiationException | IllegalAccessException e) {
				e.printStackTrace();
			}
		return newInstance;
		}

	public static <S,T> List<T> listCopy(List<S> source, Class<T> target){
		List<T> list = new ArrayList<>();
		if (null != source && source.size() > 0) {
			for (Object obj : source) {
				list.add(BeanCopy.singleCopy(obj, target));
			}
		}
		return list;
	}
}
